#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int>  G(n);

  for (int i = 0; i < n; i++) {
    G[i] = i;
  }
  do {
    for (int   k :  G) {
      cout << k << " ";
    }
    cout << endl;

  } while (next_permutation (G.begin(), G.end()));

  return   0;
}